/**
 * fulihui.com Inc.
 * Copyright (c) 2015-2016 All Rights Reserved.
 */
package com.fulihui.integral.core.biz.utils;

import com.fulihui.integral.core.biz.model.StatQueryModel;
import org.near.toolkit.common.DateUtils;

import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/**
 * 统计查询日期工具
 *
 * @author yunfeng.li
 * @version $Id: v 0.1 2017年05月04日 13:20 yunfeng.li Exp $
 */
public class StatQueryDateUtil {

    public static StatQueryModel getMonthFirstAndLastDay(String queryMonth) throws ParseException {
        Calendar calendar = new GregorianCalendar();
        Date date = DateUtils.parse(queryMonth, "yyyy-MM");
        calendar.setTime(date);
        calendar.add(calendar.DATE, 0);
        String startTime = DateUtils.format(calendar.getTime(), "yyyy-MM-dd") + " 00:00:00";
        calendar.roll(calendar.DATE, -1);
        String endTime = DateUtils.format(calendar.getTime(), "yyyy-MM-dd") + " 23:59:59";
        StatQueryModel model = new StatQueryModel();
        model.setStartDate(startTime);
        model.setEndDate(endTime);
        return model;
    }

    public static StatQueryModel getNowDay() {
        Calendar c = Calendar.getInstance();
        c.set(Calendar.HOUR_OF_DAY, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);
        Date date = c.getTime();
        String startTime = DateUtils.format(date, "yyyy-MM-dd") + " 00:00:00";
        String endTime = DateUtils.format(date, "yyyy-MM-dd") + " 23:59:59";
        StatQueryModel model = new StatQueryModel();
        model.setStartDate(startTime);
        model.setEndDate(endTime);
        return model;
    }

    public static Date getNowDate() {
        Calendar c = Calendar.getInstance();
        c.set(Calendar.HOUR_OF_DAY, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);
        Date date = c.getTime();
        return date;
    }
}